import Vue from 'vue'
import VueRouter from 'vue-router'
import HomePage from '../views/HomePage.vue'
import login from '../views/login/login.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: login,
    beforeEnter(to, from, next) {
      const { token } = localStorage;
      token ? next({ name: "home" }) : next();
      // next();继续展示当前页面
    }
  },
  {
    path: '/homePage',
    name: 'home',
    component: HomePage
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
